<template>
  <view class="page flex-col">
    <view class="group_3 flex-col">
      <view class="text-wrapper_1 flex-row">
        <text class="text_3">基本信息</text>
      </view>
      <view class="section_1 flex-row">
        <view class="box_1 flex-row red">
          <view class="flex-row align-center justify-start">
            <image
              class="image_2 ml_40"
              referrerpolicy="no-referrer"
              src="@/assets/lanhu_66iliao_2/SketchPng80187f721c8fcea72e0f31a94cc9d8717572b26100ba80131602a389d19707fa.png"
            />
            <text class="text-group_1 txt ml_20">姓名:</text>
            <nut-input class="wp100 noborder" v-model="submitmain.name" placeholder="必填项" />
          </view>
        </view>
      </view>
      <!-- <view class="section_1 flex-row">
        <view class="box_1 flex-row red">
          <view class="flex-row align-center justify-start">
            <image
              class="image_2 ml_40"
              referrerpolicy="no-referrer"
              src="@/assets/images/tel.png"
            />
            <text class="text-group_1 txt ml_20">电话:</text>
            <nut-input class="wp100 noborder" v-model="submitmain.tel" placeholder="必填项" />
          </view>
        </view>
      </view> -->
      <view class="section_1 mt-6 flex-row">
        <view class="box_1 flex-row">
          <view class="flex-row align-center justify-start red">
            <image class="image_2 ml_40 sex" referrerpolicy="no-referrer" src="@/assets/lanhu_66iliao_2/sex.png" />
            <text class="text-group_1 txt ml_20 ml_16">性别:</text>
            <view class="align-center justify-start">
              <radio-group @change="onChange">
                <label v-for="item in list" class="checkbox-list__label">
                  <radio
                    class="checkbox-list__checkbox ml_40 txt"
                    color="#fd775"
                    :value="item.value"
                    :checked="item.checked"
                    >{{ item.text }}</radio
                  >
                </label>
              </radio-group>
            </view>
          </view>
        </view>
      </view>
      <view class="flex-row">
        <view class="section_3 flex-row red">
          <view class="box_1 flex-row">
            <view class="flex-row align-center justify-start">
              <image
                class="image_2 ml_40"
                referrerpolicy="no-referrer"
                src="@/assets/lanhu_66iliao_2/SketchPng52ac28ce1b30c89f88795cb1fe895a4c7a7d4a9ad58f1911b5cf4372c548ca4e.png"
              />
              <text class="text-group_1 txt ml_20">年龄:</text>
              <nut-input class="wp100 noborder" v-model="submitmain.age" placeholder="必填项" />
            </view>
          </view>
        </view>
      </view>
      <view class="section_1 mt-6 flex-row">
        <view class="box_1 flex-row red">
          <view class="flex-row align-center justify-start">
            <image
              class="image_2 ml_40"
              referrerpolicy="no-referrer"
              src="@/assets/lanhu_66iliao_2/SketchPngba340134becbcc7c40255186431999c3484bd2431a4d947c2bc34533e35fd85e.png"
            />
            <text class="text-group_1 txt ml_20">电话:</text>
            <nut-input class="wp100 noborder" v-model="submitmain.tel" placeholder="必填项" />
          </view>
        </view>
      </view>
      <view class="section_1 mt-6 flex-row">
        <view class="box_1 flex-row red">
          <view class="flex-row align-center justify-start">
            <image
              class="image_2 ml_40"
              referrerpolicy="no-referrer"
              src="@/assets/lanhu_66iliao_2/SketchPng7a762144f562b9cccabde54af6e1ae24d05f145064c254518183962ccca3efe9.png"
            />
            <text class="text-group_1 txt ml_20">学历:</text>
            <nut-input class="wp100 noborder" v-model="submitmain.education" placeholder="必填项" />
          </view>
        </view>
      </view>
      <view class="text-wrapper_2 flex-row">
        <text class="text_7">工作信息</text>
      </view>
      <!-- <view class="section_1 flex-row">
        <view class="box_1 flex-row red">
          <view class="flex-row align-center justify-start">
            <image
              class="image_2 ml_40 imgwork"
              style="width: 90rpx"
              referrerpolicy="no-referrer"
              src="@/assets/lanhu_66iliao_2/SketchPng1f81491176a0f90446d027987488c032f435d1ef36d8d8f9d54eb42daeab3cd5.png"
            />
            <text class="text-group_1 txt ml_20">工作类型:</text>
            <view class="wp100 noborder showtype" @click="showcolum">{{
              typeof submitmain.typename == 'number' ? columns[submitmain.typename]?.text : '请选择类型'
            }}</view>
          </view>
        </view>
      </view> -->
      <view class="section_1 flex-row mt-6">
        <view class="box_1 flex-row red">
          <view class="flex-row align-center justify-start">
            <image
              class="image_2 ml_40"
              referrerpolicy="no-referrer"
              src="@/assets/lanhu_66iliao_2/SketchPng4b9f8ac68a74363b221031b6e8ebee98acd440e1d669d2e07bbd7a2f6de12bc9.png"
            />
            <text class="text-group_1 txt ml_20">现居住地:</text>
            <nut-input class="wp100 noborder" v-model="submitmain.home" placeholder="必填项" />
          </view>
        </view>
      </view>
      <!-- <view class="section_8 flex-row">
        <view class="group_6 flex-row justify-between red">
          <image
            class="thumbnail_9"
            referrerpolicy="no-referrer"
            src="@/assets/lanhu_66iliao_2/SketchPngba340134becbcc7c40255186431999c3484bd2431a4d947c2bc34533e35fd85e.png"
          />
          <image
            class="thumbnail_10"
            referrerpolicy="no-referrer"
            src="@/assets/lanhu_66iliao_2/SketchPngeec91a1fda426f4499ff0b828cab66f6be3e4060d2a685b2c1c0705edc618990.png"
          />
          <text class="text_8"> 求职意向:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </text>
        </view>
      </view> -->
      <view class="section_auto flex-row mt-6">
        <view class="box_auto flex-row red areatop">
          <view class="flex-row align-start justify-start">
            <image
              class="image_3 ml_40"
              style="margin-top: 30rpx"
              referrerpolicy="no-referrer"
              src="@/assets/lanhu_66iliao_2/SketchPng86740f178b189eee1780019d8ebffc26e456cbf4559f6749be130d63eca91ab2.png"
            />
            <text class="text-group_1 txt ml_20" style="margin-top: 30rpx"> 技能:</text>
            <nut-input
              class="wp100 noborder"
              rows="2"
              type="textarea"
              v-model="submitmain.ability"
              placeholder="必填项"
            />
          </view>
        </view>
      </view>

      <view class="box_17 flex-col">
        <view class="add_head">
          <text class="text_16">教育经历</text>
          <view @click="addediton">
            <image class="label_3" referrerpolicy="no-referrer" src="@/assets/lanhu_66wodebianjigerenziliao/add.png" />
          </view>
        </view>
        <view v-if="submitmain.educations?.length">
          <view class="workdetail" v-for="(item, ind) in submitmain.educations" :key="item">
            <view class="block_1 flex-row justify-between align-center">
              <view @click="deitordetail(item)">
                <text class="text_17">{{ item.name }}</text>
              </view>
              <view class="image-wrapper_2 flex-col" @click="deleteimg(ind)">
                <image
                  class="thumbnail_15"
                  referrerpolicy="no-referrer"
                  src="@/assets/lanhu_66wodebianjigerenziliao/delete.png"
                />
              </view>
            </view>
            <view class="block_2 flex-row" @click="deitordetail(item)">
              <text class="text_19">{{ item?.major }}</text>
              <view class="image-wrapper_3 flex-col">
                <!-- <image
                  class="thumbnail_16"
                  referrerpolicy="no-referrer"
                  src="@/assets/lanhu_66wodebianjigerenziliao/zero.png"
                /> -->
              </view>
              <!-- <text class="text_20">{{item?.major}}</text> -->
            </view>
            <view class="text-wrapper_11 flex-row" @click="deitordetail(item)">
              <text class="text_23">{{ geyDay(item?.start_time) }}-{{ geyDay(item?.end_time) }}</text>
            </view>
          </view>
        </view>
      </view>
      <view class="box_17 flex-col">
        <view class="add_head">
          <text class="text_16">工作经历</text>
          <view @click="addexper">
            <image class="label_3" referrerpolicy="no-referrer" src="@/assets/lanhu_66wodebianjigerenziliao/add.png" />
          </view>
        </view>
        <view v-if="submitmain.experiences?.length">
          <view class="workdetail" v-for="(item, ind) in submitmain.experiences" :key="item">
            <view class="block_1 flex-row justify-between align-center">
              <text class="text_17" @click="deitorworkdetail(item)">{{ item.name }}</text>
              <view class="image-wrapper_2 flex-col" @click="deleteimg1(ind)">
                <image
                  class="thumbnail_15"
                  referrerpolicy="no-referrer"
                  src="@/assets/lanhu_66wodebianjigerenziliao/delete.png"
                />
              </view>
            </view>
            <view class="block_2 cloumn flex-row" @click="deitorworkdetail(item)">
              <text class="text_19">{{ item?.position }}</text>
              <view class="image-wrapper_3 flex-col">
                <!-- <image
                  class="thumbnail_16"
                  referrerpolicy="no-referrer"
                  src="@/assets/lanhu_66wodebianjigerenziliao/zero.png"
                /> -->
              </view>
              <text class="text_20">{{ item?.performance }}</text>
            </view>
            <view class="text-wrapper_11 flex-row" @click="deitorworkdetail(item)">
              <text class="text_23">{{ geyDay(item?.start_time) }}-{{ geyDay(item?.end_time) }}</text>
            </view>
          </view>
        </view>
      </view>
      <nut-picker v-model:visible="show" :columns="columns" title="工作类型" @change="change" @confirm="confirm">
      </nut-picker>
      <view class="section_13 flex-row justify-between">
        <view class="text-wrapper_5 border flex-col" @click="cancel()">
          <text class="text_11">取消</text>
        </view>
        <view class="text-wrapper_6 flex-col" @click="submit">
          <text class="text_12">保存</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import '@/static/common.less';
import './index.less';
import { getCurrentInstance, reactive, ref, toRaw } from 'vue';
import Taro, {
  useLoad,
  usePullDownRefresh,
  useReachBottom,
  useShareAppMessage,
  useShareTimeline,
  useTitleClick,
  useDidShow,
} from '@tarojs/taro';
import { CategoryType, getCategoriesApi } from '@/api/categories';
import ProtoList from '@/components/proto-list/index.vue';
// import LoadMoreBottom from '@/components/load-more-bottom/index.vue';
import { getProtoListApi, ProtoType, Infouser } from '@/api/proto';
import SimpleTabs from '@/components/simple-tabs/index.vue';
import { ecruitresume, resumedetail,createmecard } from '@/api/moredetail';
import { showerr, geyDay } from '@/utils/common';
const container2 = ref(null);
let userinfo = Taro.getStorageSync('useInfo'); //用户信息

// const windowInfo = Taro.getWindowInfo();
// const { proxy } = getCurrentInstance();
const query = ref({
  page: 1,
  limit: 6,
  category_id: '',
  sort_by: '',
  keywords: '',
});
const submitmain = ref<Infouser>({
  user_id: -1,
  name: '',
  avatar: '',
  job_intention: '', //求职意向
  sex: 0,
  home: '', //居住地
  age: '', //年龄
  english: '', //应用名字
  tel: '',
  typename: '',
  email: '',
  ability: '', //专业技能
  personal_summary: '', //个人总结
  intentions: [], //求职意向
  educations: [], //教育经历
  projects: [], //项目经理
  experiences: [],
});
let iscreateword = false

const addediton = () => {
  Taro.getStorageSync('editorEduction') && Taro.removeStorageSync('editorEduction');
  Taro.navigateTo({ url: `/pages/userinfo/edidution/index` });
};
const addexper = () => {
  Taro.getStorageSync('deitorworkdetail') && Taro.removeStorageSync('deitorworkdetail');
  Taro.navigateTo({ url: `/pages/userinfo/workdetail/index` });
};
useDidShow(() => {
  let obj = Taro.getStorageSync('edidutionobj');
  if (obj) {
    //教育经历
    Taro.removeStorageSync('edidutionobj');
    let data = JSON.parse(obj);
    let findindex = submitmain.value.educations.findIndex((item) => item.id == data.id);
    if (findindex > -1) {
      submitmain.value.educations[findindex] = data;
    } else {
      delete data.id;
      submitmain.value.educations = submitmain.value.educations.concat(data);
    }
  }

  let workobj = Taro.getStorageSync('workobj'); ///工作经历
  if (workobj) {
    //龚总经历
    Taro.removeStorageSync('workobj');
    let data = JSON.parse(workobj);

    let ind = submitmain.value.experiences.findIndex((item) => item.id == data.id);
    if (ind > -1) {
      submitmain.value.experiences[ind] = data;
    } else {
      delete data.id;
      submitmain.value.experiences = submitmain.value.experiences.concat([data]);
    }
  }

  // workobj
});
const deleteimg = (ind) => {
  submitmain.value.educations.splice(ind, ind + 1, 0);
  let arr = [];
  submitmain.value.educations.forEach((item, index) => {
    if (index !== ind) {
      arr.push(item);
    }
  });
  submitmain.value.educations = arr;
};
const deitordetail = (detail) => {
  Taro.setStorageSync('editorEduction', JSON.stringify(detail));
  Taro.navigateTo({ url: `/pages/userinfo/edidution/index` });
};
const deitorworkdetail = (detail) => {
  Taro.setStorageSync('deitorworkdetail', JSON.stringify(detail));
  Taro.navigateTo({ url: `/pages/userinfo/workdetail/index` });
};
const deleteimg1 = (ind) => {
  submitmain.value.experiences.splice(ind, ind + 1, 0);
  let arr = [];
  submitmain.value.experiences.forEach((item, index) => {
    if (index !== ind) {
      arr.push(item);
    }
  });
  submitmain.value.experiences = arr;
};
const cancel = () => {
  Taro.navigateBack();
};
const toSearch = () => {
  Taro.navigateTo({ url: '/pages/search/index' });
};
let list = reactive([
  { value: 1, text: '男', checked: true },
  { value: 0, text: '女', checked: false },
]);
const categories = ref<CategoryType[]>([]);
const protoItems = ref<ProtoType[]>([]);
let selectval = ref([]);
const tab1value = ref('0');
const onChange = (e) => {
  submitmain.value.sex = Number(e?.detail?.value);
};
const show = ref(false);
const desc = ref('');
const columns = ref([
  { text: '全职', value: 0 },
  { text: '兼职', value: 1 },
  { text: '小时工', value: 2 },
]);
const handleProtoClick = (proto: ProtoType) => {
  console.log(handleProtoClick);
};
const change = (val) => {
  console.log(handleProtoClick);
};
const confirm = (val) => {
  let ind = toRaw(val.selectedValue)[0];
  submitmain.value.typename = ind;
  show.value = false;
};
const showcolum = () => {
  show.value = true;
};



let createWord = true //创建简历
const submit = () => {
  let usercontent = userinfo && JSON.parse(userinfo);
  let fun 
  if(createWord){
    fun = createmecard //创建简历接口
  } else {
    fun = ecruitresume //更新简历接口
  }
  fun({ id: usercontent?.id || 4, params: submitmain.value }).then((res: any) => {
    showerr(res?.message);
    if (res.code == 1010) {
      cancel();
    } 
  });
};

const getbase = () => { //初始化获取简历信息
  let usercontent = userinfo && JSON.parse(userinfo);
  resumedetail({ id: usercontent?.id || 4 }).then((res: any) => {
    let length = Object.keys(res);
    if (length) {
      createWord = false
      submitmain.value = res;
    }
    submitmain.value.user_id = usercontent?.id;
  });
};
// const refreshLoading = ref(false);
// const getProtoList = () =>ut-sticky {
//   if (protoListLoading.value === true) {
//     return;
//   }
//   query.value.page = 1;
//   protoListLoading.value = true;
//   refreshLoading.value = true;
//   getProtoListApi(query.value)
//     .then((res) => {
//       if (res.success) {
//         protoItems.value = res.result.items;
//         protoTotal.value = res.result.total;
//         noMore.value = !res.result || !res.result.total || res.result.total < query.value.limit;
//       }
//     })
//     .finally(() => {
//       protoListLoading.value = false;
//       refreshLoading.value = false;
//     });
// };
// const moreLoading = ref(false);
// const loadMore = () => {
//   if (moreLoading.value || noMore.value) {
//     return;
//   }
//   moreLoading.value = true;
//   query.value.page += 1;
//   setTimeout(() => {
//     getProtoListApi(query.value)
//       .then((res) => {
//         if (res.success) {
//           if (res.result.items && res.result.items.length) {
//             protoItems.value = protoItems.value.concat(res.result.items);
//             protoTotal.value = res.result.total;
//             noMore.value = !res.result || !res.result.total || res.result.total < query.value.limit;
//           } else {
//             noMore.value = true;
//           }
//         }
//       })
//       .finally(() => {
//         moreLoading.value = false;
//       });
//   }, 100);
// };
// useShareAppMessage((res) => {
//   if (res.from === 'button') {
//     // 来自页面内转发按钮
//     console.log(res.target);
//   }
//   return {
//     title: '抖带选 - 抖音达人带货选品快速变现平台',
//   };
// });

// const handleTabClick = (tab) => {
//   console.log(tab);
//   if (!tab) {
//     return;
//   }
//   query.value.category_id = tab.id;
//   getProtoList();
// };
// useShareTimeline(() => {
//   console.log('分享朋友圈');
//   return {};
// });

// usePullDownRefresh(() => {
//   console.log('下拉');
//   setTimeout(() => {
//     getCategories();
//     getProtoList();
//     Taro.stopPullDownRefresh();
//   }, 300);
// });
// useTitleClick(() => {
//   console.log('标题点击');
// });
// useReachBottom(() => {
//   console.log('底部');
//   loadMore();
// });
useLoad(() => {
  getbase();
});
</script>
